#### loading data ####
women.MPs.data <- read.csv("women_MPs_data.csv")

women.MPs.data$percent <- women.MPs.data$women * 100 / women.MPs.data$seats
women.MPs.data$LDP.percent <- 
   women.MPs.data$LDP.women * 100 / women.MPs.data$LDP.seats
women.MPs.data$non.LDP.percent <- 
   women.MPs.data$non.LDP.women * 100 / women.MPs.data$non.LDP.seats

women.MPs.data.HoR <- subset(women.MPs.data, type == "Lower")
women.MPs.data.HoC <- subset(women.MPs.data, type == "Upper")

#### gender disparity in Japanese bicameral legislature ####
## Figure 1
cairo_pdf("Figure_1.pdf", width = 5, height = 3, pointsize = 9)
par(mar = c(3.5, 3.5, 1, 1), lwd = 0.5)
plot(NULL, NULL, type = "n", bty = "L", xlim = c(1950, 2022), ylim = c(0, 27), 
     main = "", xlab = "", ylab = "", xaxt = "n", yaxt = "n")
abline(h = seq(0, 25, 5), lty = 3, col = "gray80")
lines(women.MPs.data.HoC$year, women.MPs.data.HoC$percent, 
      type = "o", lty = 2, lwd = 1, pch = 17)
lines(women.MPs.data.HoR$year, women.MPs.data.HoR$percent, 
      type = "o", lwd = 1, pch = 19)
axis(1, at = seq(1960, 2020, 20), lwd = 0.5)
axis(2, at = seq(0, 25, 5), lwd = 0.5)
mtext("Year", side = 1, line = 2.5)
mtext("% of woman legislators", side = 2, line = 2.5)
text(2022, women.MPs.data.HoC$percent[nrow(women.MPs.data.HoC)], 
     "HoC", pos = 3)
text(2022, women.MPs.data.HoR$percent[nrow(women.MPs.data.HoR)], 
     "HoR", pos = 3)
dev.off()

# average percentage of female HoC MPs since 2016
round(mean(women.MPs.data.HoC$percent[women.MPs.data.HoC$year >= 2016]), 1)

#### gender disparity in LDP and non-LDP legislators ####
## Figure A1
cairo_pdf("Figure_A1.pdf", width = 6, height = 2.5, pointsize = 7)
layout(matrix(1:2, 1, 2))
par(mar = c(3.5, 3.5, 3, 1), lwd = 0.5)
plot(NULL, NULL, type = "n", bty = "L", xlim = c(1958, 2022), ylim = c(0, 38), 
     main = "LDP legislators", xlab = "", ylab = "", xaxt = "n", yaxt = "n")
abline(h = seq(0, 35, 5), lty = 3, col = "gray80")
lines(women.MPs.data.HoC$year, 
      women.MPs.data.HoC$LDP.percent, 
      type = "o", lty = 2, lwd = 1, pch = 17)
lines(women.MPs.data.HoR$year, 
      women.MPs.data.HoR$LDP.percent, 
      type = "o", lwd = 1, pch = 19)
axis(1, at = seq(1960, 2020, 20), lwd = 0.5)
axis(2, at = seq(0, 35, 5), lwd = 0.5)
mtext("Year", side = 1, line = 2.5)
mtext("% of woman legislators", side = 2, line = 2.5)
text(2022, women.MPs.data.HoC$LDP.percent[nrow(women.MPs.data.HoC)], 
     "HoC", pos = 3)
text(2022, women.MPs.data.HoR$LDP.percent[nrow(women.MPs.data.HoR)], 
     "HoR", pos = 3)
plot(NULL, NULL, type = "n", bty = "L", xlim = c(1958, 2022), ylim = c(0, 38), 
     main = "Non-LDP legislators", xlab = "", ylab = "", xaxt = "n", yaxt = "n")
abline(h = seq(0, 35, 5), lty = 3, col = "gray80")
lines(women.MPs.data.HoC$year, 
      women.MPs.data.HoC$non.LDP.percent, 
      type = "o", lty = 2, lwd = 1, pch = 17)
lines(women.MPs.data.HoR$year, 
      women.MPs.data.HoR$non.LDP.percent, 
      type = "o", lwd = 1, pch = 19)
axis(1, at = seq(1960, 2020, 20), lwd = 0.5)
axis(2, at = seq(0, 35, 5), lwd = 0.5)
mtext("Year", side = 1, line = 2.5)
mtext("% of woman legislators", side = 2, line = 2.5)
text(2022, women.MPs.data.HoC$non.LDP.percent[nrow(women.MPs.data.HoC)], 
     "HoC", pos = 3)
text(2022, women.MPs.data.HoR$non.LDP.percent[nrow(women.MPs.data.HoR)], 
     "HoR", pos = 3)
dev.off()
